<template>
	<view>
		<!-- 地址 -->
		<navigator v-if="type=='1'&&info.issend==1"
			:url="'/pages/address/address?type='+type+'&source=1&cartids='+cartids+'&zhiboid='+zhiboid"
			class="address-section">
			<view class="order-content" v-if="info.address!=null">
				<text class="yticon icon-shouhuodizhi"></text>
				<view class="cen">
					<view class="top">
						<text class="name">{{info.address.realname}}</text>
						<text class="mobile">{{info.address.mobile}}</text>
					</view>
					<text
						class="address">{{info.address.province}}{{info.address.city}}{{info.address.area}}{{info.address.address}}</text>
				</view>
				<text class="yticon icon-you"></text>
			</view>
			<view class="order-content" v-else>
				<text class="yticon icon-shouhuodizhi"></text>
				<view class="cen">
					<view class="top">
						请添加收货地址
					</view>
				</view>
				<text class="yticon icon-you"></text>
			</view>
		</navigator>
		<!-- 切换配送方式 -->
		<!-- <view class="change_delivery" v-if="isVip==1">
			<view class="c_d_item" @click="changeDelivery(2)" :class="{'c_d_active':type==2}">邮寄</view>
			<view class="c_d_item" @click="changeDelivery(3)" :class="{'c_d_active':type==3}">自提</view>
		</view> -->
		<!-- 地址 -->
		<navigator v-if="(type=='2'&&info.issend==1)||(type==2&&isVip==1)"
			:url="'/pages/address/address?type='+type+'&id='+id+'&optionid='+optionid+'&total='+total+'&source=2'+'&zhiboid='+zhiboid+'&isVip='+isVip+'&isGroupBuy='+isGroupBuy"
			class="address-section">
			<view class="order-content" v-if="info.address!=null">
				<text class="yticon icon-shouhuodizhi"></text>
				<view class="cen">
					<view class="top">
						<text class="name">{{info.address.realname}}</text>
						<text class="mobile">{{info.address.mobile}}</text>
					</view>
					<text
						class="address">{{info.address.province}}{{info.address.city}}{{info.address.area}}{{info.address.address}}</text>
				</view>
				<text class="yticon icon-you"></text>
			</view>
			<view class="order-content" v-else>
				<text class="yticon icon-shouhuodizhi"></text>
				<view class="cen">
					<view class="top">
						请添加收货地址
					</view>
				</view>
				<text class="yticon icon-you"></text>
			</view>
		</navigator>

		<!-- 自提点 -->
		<view v-if="type==3" >
			<view class="address-section" style="border-bottom: 1rpx solid #eee;" @click="$navTo('/pages/address/pickupPerson?type='+type+'&id='+id+'&optionid='+optionid+'&total='+total+'&source=2'+'&zhiboid='+zhiboid+'&isVip='+isVip)">
				<view class="order-content" v-if="info.address!=null">
					<uni-icons type="staff" color="#888" size="22" style="width: 90rpx;text-align: center;"></uni-icons>
					<view class="cen">
						<view class="top">
							<text class="name">提货人：{{info.address.realname}}：{{info.address.mobile}}</text>
						</view>
					</view>
					<text class="yticon icon-you"></text>
				</view>
				<view class="order-content" v-else>
					<uni-icons type="staff" color="#888" size="22" style="width: 90rpx;text-align: center;"></uni-icons>
					<view class="cen">
						<view class="top">
							创建提货人信息
						</view>
					</view>
					<text class="yticon icon-you"></text>
				</view>
			</view>
			<view class="address-section" @click="openpickup">
				<view class="order-content" v-if="pickupSelcted.id">
					<text class="yticon icon-shouhuodizhi"></text>
					<view class="cen">
						<view class="top">
							<text class="name">自提点：{{pickupSelcted.title}}</text>
						</view>
						<text class="address">{{pickupSelcted.address}} <text style="padding-left:10rpx;color:red;">距您{{pickupSelcted.distance}}</text></text>
					</view>
					<text class="yticon icon-you"></text>
				</view>
				<view class="order-content" v-else>
					<text class="yticon icon-shouhuodizhi"></text>
					<view class="cen">
						<view class="top">
							选择提货地址
						</view>
					</view>
					<text class="yticon icon-you"></text>
				</view>
			</view>
		</view>
		<view class="" v-for="(item,isindex) in info.order_all">
			<view class="goods-section">
				<view class="g-header b-b">
					<text class="name">{{item.supplier_name}}</text>
				</view>
				<!-- 商品列表 -->
				<view class="g-item" v-for="shops in item.goods">
					<image :src="shops.thumb"></image>
					<view class="right">
						<text class="title clamp">{{shops.title}}</text>
						<text class="spec" v-if="shops.optiontitle">{{shops.optiontitle}}</text>
						<view class="price-box">
							<text class="price">￥{{shops.marketprice}}</text>
							<text class="number">x {{shops.total}}</text>
						</view>
					</view>
				</view>
			</view>
			<view class="yt-list">
				<view class="yt-list-cell b-b">
					<text class="cell-tit clamp">
						共{{item.total}}件商品
					</text>
					<text class="cell-tip">
						合计：￥{{item.goodsprice}}
					</text>
					<text class="cell-more wanjia wanjia-gengduo-d"></text>
				</view>
			</view>
			<!-- 支付方式 -->
			<view class="yt-list">
				<view class="yt-list-cell b-b">
					<text class="cell-tit">是否使用米券<text style="color:#8405dc">（可用{{info.feemoney}}米券）</text></text>
					<switch @change="switch1Change" />
				</view>
			</view>
			<!-- 优惠明细 -->
			<view class="yt-list">
				<view v-if="payIndex==0" class="yt-list-cell b-b" @click="toggleMask('show',item,isindex)">
					<view class="cell-icon">
						券
					</view>
					<text class="cell-tit clamp">优惠券</text>
					<text class="cell-tip active" v-if="!item.couponinfo">
						选择优惠券
					</text>
					<text class="cell-tip active" v-else>
						{{item.couponinfo.couponname}}
					</text>
					<text class="cell-more wanjia wanjia-gengduo-d"></text>
				</view>
				<view class="yt-list-cell b-b" v-if="item.saleset && item.saleset.showenough">
					<view class="cell-icon hb">
						减
					</view>
					<text class="cell-tit clamp">单笔满{{item.saleset.enoughmoney}}元立减</text>
					<text class="cell-tip disabled">-¥{{item.saleset.enoughdeduct}}</text>
				</view>
			</view>
			<!-- 金额明细 -->
			<view class="yt-list">
				<!-- <view class="yt-list-cell b-b">
					<text class="cell-tit clamp">商品总计</text>
					<text class="cell-tip active">¥{{Math.round((item.goodsprice)*100)/100}}</text>
				</view> -->
				<view class="yt-list-cell b-b" v-show="isMi">
					<text class="cell-tit clamp">米券抵扣</text>
					<!-- <text class="cell-tip active" style="color: #909399;">{{info.feemoney}}</text> -->
					<input type="number" class="text-right" @input="changeInput" v-model="mpay" placeholder="输入米券抵扣数量">
				</view>
				<view class="yt-list-cell b-b">
					<text class="cell-tit clamp">折扣</text>
					<text class="cell-tip active" style="color: #909399;">-¥{{item.discountprice}}</text>
				</view>
				<view class="" v-if="item.deductcredit >0 || item.deductcredit2>0">
				</view>
				
				<view class="yt-list-cell b-b" v-if="item.dispatch_price>0">
					<text class="cell-tit clamp">运费</text>
					<text class="cell-tip">+¥{{item.dispatch_price}}</text>
				</view>
				<view class="yt-list-cell b-b">
					<text class="cell-tit clamp">合计</text>
					<text
						class="cell-tip active">¥{{(nitialvalue+dispatch_price-couponinfobackmoney-vipprice).toFixed(2)}}</text>
				</view>

				<view class="yt-list-cell desc-cell">
					<text class="cell-tit clamp">备注</text>
					<input class="desc" type="text" v-if="mobile==''" placeholder="请填写备注信息" placeholder-class="placeholder"
						@input="remake($event,isindex)" />
					<input class="desc" type="text" v-model="mobile" v-else :disabled="true" placeholder="请填写备注信息" placeholder-class="placeholder"/>
				</view>
			</view>
		</view>
		<view class="c_info" v-if="info.issend==1">
			注意：运费默认为初始运费，超重和偏远地区需要补运费差价后才可以发货，请注意接听仓库客服电话通知。
		</view>

		<view class="footer">
			<view class="price-content">
				<view style="font-weight: bold;">
					<text style="font-size: 32upx;margin-right: 5upx;">实付款</text>
					<text class="price">{{actPay}}元</text>
				</view>
			</view>
			<text class="submit" @click="submit">提交订单</text>
		</view>
		<!-- 优惠券面板 -->
		<view class="mask" :class="maskState===0 ? 'none' : maskState===1 ? 'show' : ''" @click="toggleMask">
			<view class="mask-content" @click.stop.prevent="stopPrevent">
				<view class="coupon-item" v-for="(item,indexs) in couponList" :key="indexs" @tap="Choice(item)">
					<view class="con">
						<view class="left">
							<text class="title">{{item.couponname}}</text>
							<text class="time">有效期至{{item.timestr}}</text>
						</view>
						<view class="right">
							<text class="price">{{item.deduct}}</text>
							<text>{{item.backstr}}</text>
						</view>

						<view class="circle l"></view>
						<view class="circle r"></view>
					</view>
				</view>
			</view>
		</view>
		<view class="pickup" v-if="isPickup">
			<scroll-view scroll-y="true" class="p_scroll">
				<view class="p_item" v-for="item in pickupList">
					<view class="p_top">
						<image :src="item.thumb"></image>
						<view class="p_info">
							<view class="p_tit">{{item.title}}</view>
							<view class="p_address">{{item.address}}</view>
							<view class="p_address">距您{{item.distance}}</view>
						</view>
					</view>
					<view class="p_btn" @click="selectPickup(item)">选这个</view>
				</view>
			</scroll-view>
		</view>
		<uni-popup ref="bind" type="dialog" :is-mask-click="false">
			<view class="nobind">
				<view>您还未绑定手机号</view>
				<button class="l_w_login" open-type="getPhoneNumber" @getphonenumber="getUserProfile">绑定手机号</button>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		bus
	} from '../../static/js/bus.js';
	import {mapState} from 'vuex'
	export default {
		data() {
			return {
				maskState: 0, //优惠券面板显示状态
				desc: '', //备注
				couponList: [],
				info: {
					credit: 0
				},
				type: "",
				couponindex: "",
				id: "",
				optionid: "",
				total: "",
				Paidin: "",
				nitialvalue: 0, //初始值
				dispatch_price: 0, //运费
				vipprice: 0,
				couponinfobackmoney: 0, //优惠券总价
				oldcouponinfobackmoney: 0, //优惠券总价
				cartids: "",
				freightnum: [],
				freegoods: '',
				zhiboid: '',
				rate: '',
				payIndex: 1,
				typeStatus: '0',
				isGroupBuy: 0, //1团购 2次卡,
				isPickup: 0,//显示自提点
				pickupList:[],//列表
				pickupSelcted: [],//默认自提点
				isVip: 0,
				isMi: false,
				actPay: 0,
				mpay: '',
				mobile: '',
			}
		},
		computed: {
		  	...mapState(['Location'])
		},
		onLoad(option) {
			var that = this;
			var haddre = '';
			if(option.isGroupBuy){
				this.isGroupBuy = option.isGroupBuy;
			}
			if(option.isVip){
				this.isVip = option.isVip;
			}
			if(option.mobile){
				this.mobile = option.mobile
			}
			this.rate = uni.getStorageSync('JPinTuan') == '-2' ? 1 : 0;
			if (option.type == 1) {
				that.cartids = option.cartids;
				that.type = option.type;
				if (uni.getStorageSync('addre')) {
					haddre = JSON.parse(uni.getStorageSync('addre'));
					uni.removeStorageSync('addre');
				}
				this.$axios('confirm/display', "POST", 'order', {
					cartids: that.cartids,
					rate: this.rate
				}).then(res => {
					if (res.data.code == 200) {
						that.info = res.data.data;
						if (haddre != '') {
							that.info.address = haddre;
						}
						var nitialvalue = 0;
						var dispatch_price = 0;
						let vipprice = 0;
						for (var i = 0; i < that.info.order_all.length; i++) {
							nitialvalue = nitialvalue + (Number(that.info.order_all[i].realprice) - Number(that
								.info.order_all[i].dispatch_price));
							dispatch_price = Number(dispatch_price) + Number(that.info.order_all[i]
								.dispatch_price);
							vipprice = Number(vipprice) + Number(that.info.order_all[i]
								.vipprice);
						}
						that.nitialvalue = Number(nitialvalue)
						that.dispatch_price = Number(dispatch_price)
						that.vipprice = Number(vipprice)

						that.$watch('info.address', function(v) {
							that.freight()
						})
						for (var k = 0; k < that.info.order_all.length; k++) {
							var obj = {
								totalprice: "",
								supplier_uid: "",
								goods: []
							}
							obj.totalprice = that.info.order_all[k].goodsprice - that.info.order_all[k]
								.discountprice
							obj.supplier_uid = that.info.order_all[k].supplier_uid
							for (var j = 0; j < that.info.order_all[k].goods.length; j++) {
								var goodstype = that.info.order_all[k].goods[j].goodsid + ',' + that.info
									.order_all[k].goods[j].optionid +
									',' +
									that.info.order_all[k].goods[j].total
								obj.goods.push(goodstype)
							}
							obj.goods = obj.goods.join('|')
							that.freightnum.push(obj)
						}
						that.freight()
					}
				}, (error) => {

				})
			} else if (option.type == 2) {
				that.type = option.type;
				that.id = option.id;
				that.optionid = option.optionid;
				that.total = option.total;
				that.freegoods = option.freegoods;
				that.freegoods = that.freegoods == undefined ? '0' : that.freegoods;
				that.getMiaoshaInfo();
			}else if(option.type==3){
				that.type = option.type;
				that.id = option.id;
				that.optionid = option.optionid;
				that.total = option.total;
				that.freegoods = option.freegoods;
				that.freegoods = that.freegoods == undefined ? '0' : that.freegoods;
				that.getMarketInfo();
			}
		},
		methods: {
			switch1Change(e){
				this.isMi = e.detail.value
				if(!this.isMi){
					this.mpay = '';
				}else{
					this.mpay = this.info.feemoney;
				}
				this.getAccPay();
			},
			changeInput(e){
				let value = e.detail.value;
				if(value >= this.info.feemoney){
					value = this.info.feemoney;
				} 
				this.$nextTick(function() {
					if(this.mpay>0){
						this.mpay = Number(value);
					}
					this.getAccPay();
				})
			},
			getAccPay(){
				this.actPay = (this.nitialvalue+this.dispatch_price-this.couponinfobackmoney-this.vipprice).toFixed(2);
				console.log(this.actPay)
				if(!this.isMi){
					this.actPay = (this.nitialvalue+this.dispatch_price-this.couponinfobackmoney-this.vipprice).toFixed(2);
				}else{
					if(this.actPay >= 1){//如果大于1，抵扣米券
						// 如果有小数点
						if((this.actPay+'').indexOf('.')!=-1){
							let trunc = this.actPay.split('.');
							if(trunc == this.mpay){//如相等，直接为0
								this.actPay = 0;
							}else if(trunc[0] < this.mpay){//如果支付金额小于米券，则用米券减去消费金额，并加上小数点位
								if(trunc[1].length==1){
									this.actPay = trunc[1]/10;
								}else if(trunc[1].length==2){
									this.actPay = trunc[1]/100;
								}
								this.mpay = trunc[0];
							}else{//如果支付金额大于米券，则用消费金额减去米券
								this.actPay = (this.actPay - this.mpay).toFixed(2);
							}
						}else{
							if(this.actPay <= this.mpay){
								this.actPay = 0;
							}else{
								this.actPay = (Math.trunc(this.actPay) - this.mpay).toFixed(2);
							}
						}
					}else{//如果小于1，不抵扣米券
						this.actPay = (this.nitialvalue+this.dispatch_price-this.couponinfobackmoney-this.vipprice).toFixed(2);
						this.mpay = 0;
					}
				}
			},
			changeDelivery(id){
				this.type = id;
				if(id==2){
					this.getMiaoshaInfo()
				}else{
					this.getMarketInfo();
				}
			},
			openpickup(){
				this.isPickup = 1;
			},
			selectPickup(item){
				this.isPickup = 0;
				this.pickupSelcted = item;
			},
			// 自提点列表
			getpickupList(){
				this.$axios('paymarket/getPickups', 'POST', 'order', this.Location).then((res => {
					if (res.data.code == 200) {
						this.pickupList = res.data.data.list;
						this.pickupSelcted = res.data.data.list[0];
					}
				}))
			},
			// 秒杀订单信息
			getMiaoshaInfo(){
				var that = this;
				let haddre = '';
				if (uni.getStorageSync('addre')) {
					haddre = JSON.parse(uni.getStorageSync('addre'));
					uni.removeStorageSync('addre');
				}
				that.$axios('confirm/display', "POST", 'order', {
					id: that.id,
					optionid: that.optionid,
					total: that.total,
					freegoods: that.freegoods,
					rate: that.rate
				}).then(res => {
					if (res.data.code == 200) {
						that.info = res.data.data;
						if (haddre != '') {
							that.info.address = haddre;
						}
						var nitialvalue = 0;
						var dispatch_price = 0;
						let vipprice = 0;
						for (var i = 0; i < that.info.order_all.length; i++) {
							nitialvalue = nitialvalue + that.info.order_all[i].realprice - that.info.order_all[i]
								.dispatch_price;
							dispatch_price = dispatch_price + that.info.order_all[i].dispatch_price;
							vipprice = vipprice + that.info.order_all[i].vipprice;
						}
						that.nitialvalue = Number(nitialvalue)
						that.dispatch_price = Number(dispatch_price)
						that.vipprice = Number(vipprice)
						that.$watch('info.address', function(v) {
							that.freight()
						})
						for (var k = 0; k < that.info.order_all.length; k++) {
							var obj = {
								totalprice: "",
								supplier_uid: "",
								goods: []
							}
							obj.totalprice = that.info.order_all[k].goodsprice - that.info.order_all[k]
								.discountprice
							obj.supplier_uid = that.info.order_all[k].supplier_uid
							for (var j = 0; j < that.info.order_all[k].goods.length; j++) {
								var goodstype = that.info.order_all[k].goods[j].goodsid + ',' + that.info
									.order_all[k].goods[j].optionid +
									',' +
									that.info.order_all[k].goods[j].total
								obj.goods.push(goodstype)
							}
							obj.goods = obj.goods.join('|')
							that.freightnum.push(obj)
						}
						that.freight()
					}
				}, (error) => {
				
				})
			},
			// 本地超市订单信息
			getMarketInfo(){
				this.getpickupList();
				let haddre = '';
				if (uni.getStorageSync('addre')) {
					haddre = JSON.parse(uni.getStorageSync('addre'));
					uni.removeStorageSync('addre');
				}
				var that = this;
				that.$axios('paymarket/display', "POST", 'order', {
					id: that.id,
					optionid: that.optionid,
					total: that.total,
					freegoods: that.freegoods,
					rate: that.rate
				}).then(res => {
					if (res.data.code == 200) {
						that.info = res.data.data;
						if (haddre != '') {
							that.info.address = haddre;
						}
						var nitialvalue = 0;
						var dispatch_price = 0;
						let vipprice = 0;
						for (var i = 0; i < that.info.order_all.length; i++) {
							nitialvalue = nitialvalue + that.info.order_all[i].realprice - that.info.order_all[i]
								.dispatch_price;
							dispatch_price = dispatch_price + that.info.order_all[i].dispatch_price;
							vipprice = vipprice + that.info.order_all[i].vipprice;
						}
						that.nitialvalue = Number(nitialvalue)
						that.dispatch_price = Number(dispatch_price)
						that.vipprice = Number(vipprice)
						that.$watch('info.address', function(v) {
							that.freight()
						})
						for (var k = 0; k < that.info.order_all.length; k++) {
							var obj = {
								totalprice: "",
								supplier_uid: "",
								goods: []
							}
							obj.totalprice = that.info.order_all[k].goodsprice - that.info.order_all[k]
								.discountprice
							obj.supplier_uid = that.info.order_all[k].supplier_uid
							for (var j = 0; j < that.info.order_all[k].goods.length; j++) {
								var goodstype = that.info.order_all[k].goods[j].goodsid + ',' + that.info
									.order_all[k].goods[j].optionid +
									',' +
									that.info.order_all[k].goods[j].total
								obj.goods.push(goodstype)
							}
							obj.goods = obj.goods.join('|')
							that.freightnum.push(obj)
						}
						that.freight()
					}
				}, (error) => {
				
				})
			},
			//显示优惠券面板
			toggleMask(type, item, indexs) {
				var isindex = indexs
				var that = this;
				var goodsid = '';
				if (!this.info.fromcart) {
					goodsid = this.info.goods[0].goodsid
				} else {
					goodsid = '';
				}
				if (type == 'show') {
					this.$axios('Util/query', "POST", 'coupon', {
						money: item.realprice,
						supplier_uid: item.supplier_uid,
						cartids: item.cartids,
						goodsid
					}).then(res => {
						if (res.data.code == 200) {
							if (res.data.data.coupons.length == 0) {
								uni.showToast({
									title: '无可用优惠券',
									icon: "none",
									duration: 2000
								});
							} else {
								that.couponindex = isindex
								that.couponList = res.data.data.coupons;
								let timer = type === 'show' ? 10 : 300;
								let state = type === 'show' ? 1 : 0;
								this.maskState = 2;
								setTimeout(() => {
									this.maskState = state;
								}, timer)
							}
						}
					}, (error) => {

					})
				} else {
					let timer = type === 'show' ? 10 : 300;
					let state = type === 'show' ? 1 : 0;
					this.maskState = 2;
					setTimeout(() => {
						this.maskState = state;
					}, timer)
				}
			},
			getUserProfile(e) {
				let that = this;
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						let obj = e.detail;
						obj.code1 = loginRes.code;
						that.$axios('bindmobile/bmobile', "POST", 'member', obj).then(res => {
							if (res.data.code == 200) {
								that.$refs.bind.close();
								that.submitReal();
							}
						})
					},
					fail() {
						that.$api.msg('绑定失败，请重试！')
					}
				})
			},
			submit() {
				// 判断是否绑定手机号
				// var that = this;
				// that.$axios('Info/member_info', "POST", 'member').then(res => {
				// 	if (res.data.code = 200) {
				// 		if(res.data.data.member.mobile==''||res.data.data.member.mobile.length<1||res.data.data.member.mobile===null||res.data.data.member.mobile==undefined){
				// 			that.$refs.bind.open();
				// 		}else{
				// 			this.submitReal();
				// 		}
				// 	}
				// })
				this.submitReal();
			},
			// 提交订单
			submitReal() {
				var that = this;
				if (this.info.issend == 1 && !that.info.address || (that.info.address && !that.info.address.id)) {
					this.$api.msg('请完善地址信息！');
					return;
				}
				if(this.type==3){
					if(!that.info.address) return this.$api.msg('请先创建提货人信息！');
				}
				// if(this.isVip==1&&!that.info.address){
				// 	return this.$api.msg('请完善地址信息！');
				// }
				that.freegoods = that.freegoods == undefined ? '0' : that.freegoods;
				var order = [];
				var Pto = '';
				var Pgoodsid = that.info.order_all[0].goods[0].goodsid;
				if (uni.getStorageSync('JPinTuan') && this.rate != '-2') {
					var JPinTuan = uni.getStorageSync('JPinTuan').split('||');
					if (JPinTuan[0] == Pgoodsid && JPinTuan[1] != '-1') {
						Pto = JPinTuan[1]
					}
				}
				if (that.type == 1) {
					for (var i = 0; i < that.info.order_all.length; i++) {
						var orders = {
							goods: []
						}
						orders.supplier_uid = that.info.order_all[i].supplier_uid
						for (var j = 0; j < that.info.order_all[i].goods.length; j++) {
							var goodstype = that.info.order_all[i].goods[j].goodsid + ',' + that.info.order_all[i].goods[j]
								.optionid + ',' +
								that.info.order_all[i].goods[j].total
							orders.goods.push(goodstype)
						}
						orders.goods = orders.goods.join('|')
						orders.dispatchtype = 0
						orders.fromcart = that.info.fromcart
						orders.cartids = that.cartids
						orders.remark = that.info.order_all[i].remake
						orders.deduct = 0
						orders.deduct2 = 0
						orders.yunbi = 0
						orders.addressid = that.info.address ? that.info.address.id : '';
						orders.freegoods = that.freegoods;
						orders.groupsn = Pto;
						if (that.info.order_all[i].couponinfo != '' && that.info.order_all[i].couponinfo) {
							orders.couponid = that.info.order_all[i].couponinfo.id
						}
						order.push(orders)
					}
					if (this.payIndex == 1) delete orders.couponid;
					order = JSON.stringify(order)
					this.$axios('confirm/create', "POST", 'order', {
						order,
						rate: this.rate,
						type: this.typeStatus,
						ismicredit: this.isMi&&this.mpay>0 ? 1 : 0,
						mpay: this.mpay ? this.mpay : 0

					}).then(res => {
						if (res.data.code == 200) {
							if (res.data.data.orderid == '') {
								uni.showToast({
									title: '请刷新重试',
									icon: 'none'
								})
							} else {
								uni.redirectTo({
									url: '/pages/money/pay?orderid=' + res.data.data.orderid
								})
							}
						}
					}, (error) => {

					})
				} else if (that.type == 2) {
					for (var i = 0; i < that.info.order_all.length; i++) {
						var orders = {
							goods: []
						}
						orders.supplier_uid = that.info.order_all[i].supplier_uid
						for (var j = 0; j < that.info.order_all[i].goods.length; j++) {
							if (that.freegoods == 1) {
								that.info.order_all[i].goods[j].total = 1;
							}
							var goodstype = that.info.order_all[i].goods[j].goodsid + ',' + that.info.order_all[i].goods[j]
								.optionid + ',' +
								that.info.order_all[i].goods[j].total
							orders.goods.push(goodstype)
						}
						orders.goods = orders.goods.join('|')
						orders.id = that.id
						orders.dispatchtype = 0
						orders.fromcart = that.info.fromcart
						orders.cartids = 0
						orders.remark = that.mobile!='' ? that.mobile : that.info.order_all[i].remake
						orders.deduct = 0
						orders.deduct2 = 0
						orders.yunbi = 0;
						orders.freegoods = that.freegoods;
						orders.addressid = that.info.address ? that.info.address.id : '';
						orders.groupsn = Pto;
						if (that.info.order_all[i].couponinfo != '' && that.info.order_all[i].couponinfo) {
							orders.couponid = that.info.order_all[i].couponinfo.id
						}
						order.push(orders)
					}
					if (this.payIndex == 1) delete orders.couponid;
					order = JSON.stringify(order)
					this.$axios('confirm/create', "POST", 'order', {
						order,
						rate: this.rate,
						type: this.typeStatus,
						ismicredit: this.isMi&&this.mpay>0 ? 1 : 0,
						mpay: this.mpay ? this.mpay : 0
					}).then(res => {
						if (res.data.code == 200) {
							if (res.data.data.orderid == '') {
								uni.showToast({
									title: '请刷新重试',
									icon: 'none'
								})
							} else {
								uni.redirectTo({
									url: '/pages/money/pay?orderid=' + res.data.data.orderid+'&isGroupBuy='+this.isGroupBuy+'&isVip='+this.isVip
								})
							}
						}
					}, (error) => {

					})
				} else if (that.type == 3) {
					for (var i = 0; i < that.info.order_all.length; i++) {
						var orders = {
							goods: []
						}
						orders.supplier_uid = that.info.order_all[i].supplier_uid
						for (var j = 0; j < that.info.order_all[i].goods.length; j++) {
							if (that.freegoods == 1) {
								that.info.order_all[i].goods[j].total = 1;
							}
							var goodstype = that.info.order_all[i].goods[j].goodsid + ',' + that.info.order_all[i].goods[j]
								.optionid + ',' +
								that.info.order_all[i].goods[j].total
							orders.goods.push(goodstype)
						}
						orders.goods = orders.goods.join('|')
						orders.id = that.id
						orders.dispatchtype = 0
						orders.fromcart = that.info.fromcart
						orders.cartids = 0
						orders.remark = that.info.order_all[i].remake
						orders.deduct = 0
						orders.deduct2 = 0
						orders.yunbi = 0;
						orders.freegoods = that.freegoods;
						orders.addressid = that.info.address ? that.info.address.id : '';
						// orders.storeid = that.pickupSelcted.id;
						orders.groupsn = Pto;
						if (that.info.order_all[i].couponinfo != '' && that.info.order_all[i].couponinfo) {
							orders.couponid = that.info.order_all[i].couponinfo.id
						}
						order.push(orders)
					}
					if (this.payIndex == 1) delete orders.couponid;
					order = JSON.stringify(order)
					this.$axios('paymarket/create', "POST", 'order', {
						order,
						storeid: this.pickupSelcted.id,
						rate: this.rate,
						type: this.typeStatus,
						ismicredit: this.isMi&&this.mpay>0 ? 1 : 0,
						mpay: this.mpay ? this.mpay : 0
					}).then(res => {
						if (res.data.code == 200) {
							if (res.data.data.orderid == '') {
								uni.showToast({
									title: '请刷新重试',
									icon: 'none'
								})
							} else {
								uni.redirectTo({
									url: '/pages/money/pay?orderid=' + res.data.data.orderid+'&isGroupBuy='+this.isGroupBuy
								})
							}
						}
					}, (error) => {

					})
				}
			},			
			stopPrevent() {},
			Choice(item, type) {
				var that = this;
				for (var j = 0; j < that.info.order_all.length; j++) {
					if (that.info.order_all[j].couponinfo) {
						if (that.info.order_all[j].couponinfo.id == item.id) {
							uni.showToast({
								title: '此红包已被使用',
								icon: "none",
								duration: 2000
							});
							return false
						}
					}
				}
				that.$set(that.info.order_all[that.couponindex], 'couponinfo', item)
				var num = 0
				for (var i = 0; i < that.info.order_all.length; i++) {
					if (that.info.order_all[i].couponinfo) {
						num = num + Number(that.info.order_all[i].couponinfo.backmoney)
					}
				}
				that.couponinfobackmoney = Number(num)
				that.oldcouponinfobackmoney = that.couponinfobackmoney;
				let timer = type === 'show' ? 10 : 300;
				let state = type === 'show' ? 1 : 0;
				this.maskState = 2;
				setTimeout(() => {
					this.maskState = state;
				}, timer)
			},
			freight() {
				var that = this;
				let dispatch_price = 0;
				for (var i = 0; i < that.freightnum.length; i++) {
					let isindex = i
					this.$axios('confirm/getdispatchprice', "POST", 'order', {
						totalprice: that.freightnum[i].totalprice,
						addressid: that.info.address===null ? 0 : that.info.address.id,
						supplier_uid: that.freightnum[i].supplier_uid,
						cartids: that.cartids,
						goods: that.freightnum[i].goods
					}).then(res => {
						if (res.data.code == 200) {
							that.info.order_all[isindex].dispatch_price = res.data.data.price;
							var dispatch_price = 0
							for (var k = 0; k < that.info.order_all.length; k++) {
								dispatch_price = Number(dispatch_price) + Number(that.info.order_all[k]
									.dispatch_price);
								that.$set(that.info.order_all[k], 'couponinfo', '')
								that.couponinfobackmoney = 0
							}
							that.dispatch_price = dispatch_price;
							that.getAccPay();
						}
					}, (error) => {

					})
				}
			},
			remake(e, i) {
				this.$set(this.info.order_all[i], 'remake', e.detail.value);
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: $page-color-base;
		padding-bottom: 240upx;
	}
	.change_delivery{
		display: flex;
		padding: 20rpx;
		.c_d_item{
			color: $bg-color;
			background: #fff;
			text-align: center;
			width: 140rpx;
			line-height: 60rpx;
			border-radius: 10rpx 0 0 10rpx;
		}
		.c_d_item:nth-child(2){
			border-radius: 0 10rpx 10rpx 0;
		}
		.c_d_active{
			background: $bg-color;
			color: #fff;
		}
	}
	.pickup{
		position: fixed;
		background: #fff;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		z-index: 999;
		.p_scroll{
			height: 100%;
			padding: 20rpx;
			.p_item{
				margin-bottom: 20rpx;
				padding-bottom: 60rpx;
				border-bottom: 1rpx solid #e6dcdc5c;
				.p_top{
					display: flex;
					align-items: center;
					justify-content: space-between;
					image{
						width: 120rpx;
						height: 120rpx;
						border-radius: 12rpx;
					}
					.p_info{
						flex: 1;
						padding-left: 20rpx;
						.p_tit{
							font-weight: bold;
							margin-bottom: 10rpx;
						}
						.p_address{
							font-size: 24rpx;
							color: #999;
						}
					}
				}
				.p_btn{
					width: 120rpx;
					height: 40rpx;
					border-radius: 33rpx;
					line-height: 40rpx;
					color: #fff;
					text-align: center;
					font-size: 22rpx;
					float: right;
					background: linear-gradient( 270deg, #8917E2 0%, #B92DF1 100%);
				}
			}
		}
	}
	.address-section {
		padding: 30upx 0;
		background: #fff;
		position: relative;

		.order-content {
			display: flex;
			align-items: center;
		}

		.icon-shouhuodizhi {
			flex-shrink: 0;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 90upx;
			color: #888;
			font-size: 44upx;
		}

		.cen {
			display: flex;
			flex-direction: column;
			flex: 1;
			font-size: 28upx;
			color: $font-color-dark;
		}

		.name {
			font-size: 34upx;
			margin-right: 24upx;
		}

		.address {
			margin-top: 16upx;
			margin-right: 20upx;
			color: $font-color-light;
		}

		.icon-you {
			font-size: 32upx;
			color: $font-color-light;
			margin-right: 30upx;
		}

		.a-bg {
			position: absolute;
			left: 0;
			bottom: 0;
			display: block;
			width: 100%;
			height: 5upx;
		}
	}

	.goods-section {
		margin-top: 16upx;
		background: #fff;
		padding-bottom: 1px;

		.g-header {
			display: flex;
			align-items: center;
			height: 84upx;
			padding: 0 30upx;
			position: relative;
		}

		.logo {
			display: block;
			width: 50upx;
			height: 50upx;
			border-radius: 100px;
		}

		.name {
			font-size: 30upx;
			color: $font-color-base;
			margin-left: 24upx;
		}

		.g-item {
			display: flex;
			margin: 20upx 30upx;

			image {
				flex-shrink: 0;
				display: block;
				width: 140upx;
				height: 140upx;
				border-radius: 4upx;
			}

			.right {
				flex: 1;
				padding-left: 24upx;
				overflow: hidden;
			}

			.title {
				font-size: 30upx;
				color: $font-color-dark;
			}

			.spec {
				font-size: 26upx;
				color: $font-color-light;
			}

			.price-box {
				display: flex;
				align-items: center;
				font-size: 32upx;
				color: $font-color-dark;
				padding-top: 10upx;

				.price {
					margin-bottom: 4upx;
				}

				.number {
					font-size: 26upx;
					color: $font-color-base;
					margin-left: 20upx;
				}
			}

			.step-box {
				position: relative;
			}
		}
	}

	.yt-list {
		margin-top: 16upx;
		background: #fff;
	}

	.yt-list-cell {
		display: flex;
		align-items: center;
		padding: 10upx 30upx 10upx 40upx;
		line-height: 70upx;
		position: relative;

		&.cell-hover {
			background: #fafafa;
		}

		&.b-b:after {
			left: 30upx;
		}

		.cell-icon {
			height: 32upx;
			width: 32upx;
			font-size: 22upx;
			color: #fff;
			text-align: center;
			line-height: 32upx;
			background: #f85e52;
			border-radius: 4upx;
			margin-right: 12upx;

			&.hb {
				background: #ffaa0e;
			}

			&.lpk {
				background: #3ab54a;
			}

		}

		.cell-more {
			align-self: center;
			font-size: 24upx;
			color: $font-color-light;
			margin-left: 8upx;
			margin-right: -10upx;
		}

		.cell-tit {
			flex: 1;
			font-size: 26upx;
			color: $font-color-light;
			margin-right: 10upx;
		}

		.cell-tip {
			font-size: 26upx;
			color: $font-color-dark;

			&.disabled {
				color: $font-color-light;
			}

			&.active {
				color: $base-color;
			}

			&.red {
				color: #e10602;
			}
		}

		&.desc-cell {
			.cell-tit {
				max-width: 90upx;
			}
		}

		.desc {
			flex: 1;
			font-size: $font-base;
			color: $font-color-dark;
		}
	}

	/* 支付列表 */
	.pay-list {
		padding-left: 40upx;
		margin-top: 16upx;
		background: #fff;

		.pay-item {
			display: flex;
			align-items: center;
			padding-right: 20upx;
			line-height: 1;
			height: 110upx;
			position: relative;
		}

		.icon-weixinzhifu {
			width: 80upx;
			font-size: 40upx;
			color: #6BCC03;
		}

		.icon-alipay {
			width: 80upx;
			font-size: 40upx;
			color: #06B4FD;
		}

		.icon-xuanzhong2 {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 60upx;
			height: 60upx;
			font-size: 40upx;
			color: $base-color;
		}

		.tit {
			font-size: 32upx;
			color: $font-color-dark;
			flex: 1;
		}
	}

	.shell_input {
		background: #FFFFFF;
		border-bottom: 1px hsl(0, 0%, 87%) solid;
		display: flex;
		align-items: center;
		padding: 0 30upx;
		position: fixed;
		bottom: 140upx;
		height: 90upx;
		width: 100%;
		z-index: 998;
	}

	.shell_input input {
		flex: 1;
		font-size: 26upx;
	}

	.shell_input text {
		color: #0062CC;
	}

	.footer {
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 995;
		display: flex;
		align-items: center;
		width: 100%;
		height: 140upx;
		font-size: 30upx;
		background-color: #fff;
		z-index: 998;
		color: $font-color-base;

		.price-content {
			padding-left: 30upx;
			font-size: 22upx;
			flex: 1;
		}

		.price-tip {
			color: $base-color;
			margin-left: 8upx;
		}

		.price {
			font-size: 40upx;
			color: $base-color;
		}

		.submit {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 170upx;
			height: 100%;
			color: #fff;
			font-size: 28upx;
			background-color: $base-color;
		}
	}

	/* 优惠券面板 */
	.mask {
		display: flex;
		align-items: flex-end;
		position: fixed;
		left: 0;
		top: var(--window-top);
		bottom: 0;
		width: 100%;
		background: rgba(0, 0, 0, 0);
		z-index: 9995;
		transition: .3s;

		.mask-content {
			width: 100%;
			min-height: 30vh;
			max-height: 70vh;
			background: #f3f3f3;
			transform: translateY(100%);
			transition: .3s;
			overflow-y: scroll;
		}

		&.none {
			display: none;
		}

		&.show {
			background: rgba(0, 0, 0, .4);

			.mask-content {
				transform: translateY(0);
			}
		}
	}

	/* 优惠券列表 */
	.coupon-item {
		display: flex;
		flex-direction: column;
		margin: 20upx 24upx;
		background: #fff;

		.con {
			display: flex;
			align-items: center;
			position: relative;
			height: 120upx;
			padding: 0 30upx;

			&:after {
				position: absolute;
				left: 0;
				bottom: 0;
				content: '';
				width: 100%;
				height: 0;
				border-bottom: 1px dashed #f3f3f3;
				transform: scaleY(50%);
			}
		}

		.left {
			display: flex;
			flex-direction: column;
			justify-content: center;
			flex: 1;
			overflow: hidden;
			height: 100upx;
		}

		.title {
			font-size: 32upx;
			color: $font-color-dark;
			margin-bottom: 10upx;
		}

		.time {
			font-size: 24upx;
			color: $font-color-light;
		}

		.right {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			font-size: 26upx;
			color: $font-color-base;
			height: 100upx;
		}

		.price {
			font-size: 44upx;
			color: $base-color;

			&:before {
				content: '￥';
				font-size: 34upx;
			}
		}

		.tips {
			font-size: 24upx;
			color: $font-color-light;
			line-height: 60upx;
			padding-left: 30upx;
		}

		.circle {
			position: absolute;
			left: -6upx;
			bottom: -10upx;
			z-index: 10;
			width: 20upx;
			height: 20upx;
			background: #f3f3f3;
			border-radius: 100px;

			&.r {
				left: auto;
				right: -6upx;
			}
		}
	}

	.c_info {
		padding: 20upx;
		box-sizing: border-box;
	}

	.pay_status {
		font-size: 24upx;
		display: flex;
		align-items: center;
		padding: 0 30upx;
	}
</style>